import { Injectable, Logger } from "@nestjs/common";
import { Cron, Interval, Timeout } from "@nestjs/schedule";

@Injectable()
export class TasksService {
    private readonly logger = new Logger(TasksService.name, {timestamp: true});

    // declare cron job
    @Cron('45 * * * * *', { name: 'every45SecondsCron' })
    handleEvery45SecondsCron() {
        this.logger.debug('Called when the current second is 45');
    }

    @Cron('30 * * * * *', { name: 'every30SecondsCron' })
    handleEvery30SecondsCron() {
        this.logger.debug('Called when the current second is 30');
    }

    // declare interval job
    @Interval('interval', 20000)
    handleIntervalJob() {
        this.logger.debug('Called every 20 seconds');
    }

    // declare timeout job
    @Timeout('timeout', 5000)
    handleTimeoutJob() {
        this.logger.debug(`Timeout job called after 5 seconds`);
    }
}

/**
* * * * * *
| | | | | |
| | | | | day of week
| | | | months
| | | day of month
| | hours
| minutes
seconds (optional)
 */

/**
* 周一至周五上午11:30
 * *   * * *  *
 0 30 11 * * 1-5
 */